function login(){
    var formdata = $('#login').serialize();
    $.ajax({
        type: "post",
        url: WWW+"index/login",
        data: formdata,
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                setInterval(function(){
                    window.location.href=WWW+"admin";
                },1500);
            }else{
                tishi('error',e.info);
            }
        }
    });
}
function add()
{
    var formdata = $('#add').serialize();
    $.ajax({
        type: "post",
        url: WWW+"admin/add",
        data: formdata,
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#addwww').modal('hide');
                setInterval(function(){
                    window.location.href=WWW+"admin/shouquan_list";
                },1500);
            }else{
                tishi('error',e.info);
            }
        }
    });
}
function edit()
{
    var formdata = $('#edit').serialize();
    $.ajax({
        type: "post",
        url: WWW+"admin/edit",
        data: formdata,
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#bianji').modal('hide');
                setInterval(function(){
                    window.location.href=WWW+"admin/shouquan_list";
                },1500);
            }else{
                tishi('error',e.info);
            }
        }
    });
}
function del()
{
    $.ajax({
        type: "post",
        url: WWW+"admin/del",
        data: {id:$('#shanchu input[name="id"]').val()},
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#shanchu').modal('hide');
                setInterval(function(){
                    window.location.href=WWW+"admin/shouquan_list";
                },1500);
            }else{
                tishi('error',e.info);
            }
        }
    });
}
function ok()
{
    var dataforum = $('#setup').serialize();
    $.ajax({
        type: "post",
        url: WWW+"admin/setup",
        data: dataforum,
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#shanchu').modal('hide');
            }else{
                tishi('error',e.info);
            }
        }
    });
}
// 修改密码
function edit_pass()
{
    var dataforum = $('#pass').serialize();
    $.ajax({
        type: "post",
        url: WWW+"admin/edit_pass",
        data: dataforum,
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#editpass').modal('hide');
            }else{
                tishi('error',e.info);
            }
        }
    });
}
function del_daoban(){
    $.ajax({
        type: "post",
        url: WWW+"admin/del_daoban",
        data: {id:$('#shanchu_daoban input[name="id"]').val()},
        dataType: "json",
        success: function (e) {
            if(e.error){
                tishi('success',e.info);
                $('#shanchu_daoban').modal('hide');
                setInterval(function(){
                    window.location.href=WWW+"admin/daoban_list";
                },1500);
            }else{
                tishi('error',e.info);
            }
        }
    });  
}
// 提示
function tishi(type,msg){
    Lobibox.notify(type, {
        iconSource: 'fontAwesome',
        soundPath:WWW+'Public/dist/sounds/',
        position: 'right top',
        msg: msg,
        icons: {
            bootstrap: {
                confirm : 'glyphicon glyphicon-question-sign',
                success : 'glyphicon glyphicon-ok-sign',
                error   : 'glyphicon glyphicon-remove-sign',
                warning : 'glyphicon glyphicon-exclamation-sign',
                info    : 'glyphicon glyphicon-info-sign'
            },
            fontAwesome: {
                confirm : 'fa fa-question-circle',
                success : 'fa fa-check-circle',
                error   : 'fa fa-times-circle',
                warning : 'fa fa-exclamation-circle',
                info    : 'fa fa-info-circle'
            }
        }
    });

}
// 修改
$('#bianji').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget) // Button that triggered the modal
    var recipient = eval('(' + button.data('whatever') + ')') // Extract info from data-* attributes
    // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
    // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
    var modal = $(this)
        state1 = recipient.state == 1 ? '<option value="1" selected="selected">开通</option>':'<option value="1">开通</option>';
        state2 = recipient.state == 0 ? '<option value="0" selected="selected">暂定授权</option>':'<option value="0">暂定授权</option>';
    var html = ['<label for="exampleFormControlSelect3">状态</label>',
                    '<select name="state" class="form-control form-control-sm" id="exampleFormControlSelect3">',
                    state1+state2,
                    '</select>'
                ].join("");
    modal.find('.modal-body input[name="id"]').val(recipient.id)
    modal.find('.modal-body input[name="domain"]').val(recipient.domain)
    modal.find('.modal-body input[name="xiangmu"]').val(recipient.xiangmu)
    modal.find('.modal-body input[name="qq"]').val(recipient.qq)
    modal.find('.modal-body .zhuangtai').html(html)
})
// 删除
$('#shanchu, #shanchu_daoban').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget) // Button that triggered the modal
    var recipient = button.data('whatever') // Extract info from data-* attributes
    var modal = $(this)
    modal.find('.modal-body input[name="id"]').val(recipient)
})

